package cn.lili.modules.share.serviceimpl;

import cn.lili.modules.share.mapper.AppHmdMapper;
import cn.lili.modules.share.service.AppHmdService;
import cn.lili.modules.share.entity.docs.AppHmd;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-03-21
 */
@Service
@Slf4j
public class AppHmdServiceImpl extends ServiceImpl<AppHmdMapper, AppHmd> implements AppHmdService {


    /**
     * 给上级推广加 1
     * @param hname
     * @return
     */
    @Override
    public Boolean shareRegisterAddOneStatistics(String hname) {
        LambdaQueryWrapper<AppHmd> query = new LambdaQueryWrapper<>();
        query.eq(true, AppHmd::getHname, hname);
        query.last("limit 1");
        AppHmd appHmd = baseMapper.selectOne(query);
        if (appHmd != null) {
            return baseMapper.shareRegisterAddOneStatistics(appHmd.getId()) > 0;
        } else {
            appHmd = new AppHmd();
            appHmd.setHname(hname);
            appHmd.setCount(1);
            appHmd.setCtime(Long.valueOf(System.currentTimeMillis() / 1000).intValue());
            return baseMapper.insert(appHmd) > 0;
        }
    }
}
